package com.shujia.core

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object Code25Partition1 {
  def main(args: Array[String]): Unit = {
    val sc = new SparkContext(new SparkConf().setMaster("local").setAppName("CoGroup"))

    val value1RDD: RDD[(String, Int)] = sc.parallelize(List(("k1", 11), ("k1", 1), ("k2", 2), ("k3", 33), ("k5", 45), ("k4", 4), ("k3", 3), ("k3", 33)), 2)
    println("value1RDD:" + value1RDD.getNumPartitions)

    val mapRDD: RDD[(String, Int)] = value1RDD
      .map(x => (x._1, x._2 * x._2))
    println("mapRDD:" + mapRDD.getNumPartitions)

    val reduceRDD: RDD[(String, Int)] = mapRDD
      .reduceByKey(_ + _, numPartitions = 3)
    println("reduceRDD:" + reduceRDD.getNumPartitions)

    reduceRDD.foreach(println)
    while (true) {

    }


  }
}
